package com.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;

public class EStest {

//    private RestHighLevelClient client;
//
//    @Test
//    void testCreateIndex() throws IOException {
//        // 2.准备Request对象
//        CreateIndexRequest request = new CreateIndexRequest("productinfos");
//        // 3.准备请求参数
//        request.source(PRODUCT_INFO_MAPPING, XContentType.JSON);
//        client.indices().create(request, RequestOptions.DEFAULT);
//    }
//
//
//    @Test
//    void testGetIndex() throws IOException {
//        // 1.准备Request对象
//        GetIndexRequest request = new GetIndexRequest("productinfos");
//        // 3.发送请求
//        boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);
//        System.out.println("exists = " + exists);
//
//    }
//
//    @Test
//    void testConnection() {
//        System.out.println("client = " + client);
//    }
//
//    @BeforeEach
//    void setUp() {
//        this.client = new RestHighLevelClient(RestClient.builder(
//                HttpHost.create("http://62.234.222.48:9200")
//        ));
//    }
//
//    @AfterEach
//    void tearDown() throws IOException {
//        if (this.client != null) {
//            this.client.close();
//        }
//    }
//
//    public static final String PRODUCT_INFO_MAPPING = "{\n" +
//            "  \"mappings\": {\n" +
//            "    \"properties\": {\n" +
//            "      \"id\": {\n" +
//            "        \"type\": \"keyword\"\n" +
//            "      },\n" +
//            "      \"title\":{\n" +
//            "        \"type\": \"text\",\n" +
//            "        \"analyzer\": \"ik_max_word\"\n" +
//            "      },\n" +
//            "      \"intro\":{\n" +
//            "        \"type\": \"text\",\n" +
//            "        \"analyzer\": \"ik_max_word\"\n" +
//            "      },\n" +
//            "      \"image\":{\n" +
//            "        \"type\": \"keyword\",\n" +
//            "        \"index\": false\n" +
//            "      },\n" +
//            "      \"price\":{\n" +
//            "        \"type\": \"integer\"\n" +
//            "      },\n" +
//            "      \"typeId\":{\n" +
//            "        \"type\": \"keyword\"\n" +
//            "      },\n" +
//            "      \"postType\":{\n" +
//            "        \"type\": \"keyword\"\n" +
//            "      },\n" +
//            "      \"updateTime\":{\n" +
//            "        \"type\": \"date\"\n" +
//            "      }\n" +
//            "    }\n" +
//            "  }\n" +
//            "}";
//

}
